export default {
  data () {
    return {
      request: {},
      loading: false,
      statusOption: [
        { value: '2', name: '全部' },
        { value: '0', name: '上架' },
        { value: '1', name: '下架' }
      ],
      pagination: {
        position: 'bottom',
        pageSizeOptions: ['10', '20', '30', '40', '50'],
        pageSize: 10,
        current: 1,
        total: 0
      },
      columns: [],
      data: [],
      queryParam: {},
      rowKey: 'id',
      selectedRowKeys: [],
      selectedRows: []
    }
  },
  async created () {
    await this.getPage()
  },
  methods: {
    async getPage () {
      this.loading = true
      console.log(this.request.page)
      const res = await this.request.page({
        pageNo: this.pagination.current,
        pageSize: this.pagination.pageSize,
        ...this.queryParam
      })
      console.log(res)
      this.data = res.data.records.map((el, index) => {
        return {
          ...el,
          index: index + 1,
          statusText: this.statusOption.find(item => Number(el.status) === Number(item.value))?.name
        }
      })
      this.pagination.total = res.data.total
      this.loading = false
    },
    handleChange (pagination) {
      this.pagination.current = pagination.current
      this.pagination.pageSize = pagination.pageSize
      this.getPage()
    },
    onSelectChange (selectedRowKeys, selectedRows) {
      this.selectedRowKeys = selectedRowKeys
      this.selectedRows = selectedRows
    },
    refresh () {
      this.pagination.current = 1
      this.getPage()
    },
    async handleDel (record) {
      await this.request.updateStatus({ id: record.id, status: -1 })
      await this.getPage()
    },
    onReset() {
      this.queryParam = {
        ...this.resetQueryParam
      }
      this.getPage()
    },
    onValidate(name = 'ruleForm', field = 'content') {
      console.log('qingkong',name,field, this.$refs[name]);
      if (this.$refs[name]) {
        this.$nextTick(() => {
          this.$refs[name].clearValidate(field)
        })
      }
    }
    
  },
  computed: {
    content() {
      return this.ruleForm.content
    }
  },
  
}
